package cn.com.sinux.spring.utils;

import java.util.UUID;

/**
 * Created by wangjie on 2016/3/16.
 */
public class AutoStr {

    /**
     * 获取时间的26进制数字
     * @return
     */
    public static String getAutoStr(){
        String str = toRadix(System.currentTimeMillis(),25);
        return str;
    }

    /**
     * 获取UUID
     * @return
     */
    public static String getAutoUUID(){
        String str = UUID.randomUUID().toString();
        return str;
    }

    /**
     * 进制转换
     * @param data 十进制数据
     * @param radix 待转换的进制
     * @return 转换后的字符串显示
     */
    public static String toRadix(long data,long radix){
        char[] digits={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
        char buf[] = new char[33];
        int charPos = 32;

        while(data>radix){
            buf[charPos--]=digits[(int) (data % radix)];
            data=data/radix;
        }
        buf[charPos] = digits[(int) data];
        return new String(buf, charPos, (33 - charPos));
    }
}
